package com.java.collection;

import java.util.HashMap;
import java.util.Map;

public class CarHashMapDemo2 {

    public static void main(String[] args) {
        //汽车集合 key司机对象 value汽车对象
        Map<Driver,Car> cars = new HashMap<>();
        //添加数据
        Driver driver1 = new Driver("老刘",20,"男");
        Driver driver2 = new Driver("小刘",20,"女");
        Driver driver3 = new Driver("老王",40,"男");
        Driver driver4 = new Driver("老李",45,"男");
        cars.put(driver1,new Car("001","BYD",200000,"白色"));
        cars.put(driver2,new Car("002","奥迪",400000,"黑色"));
        cars.put(driver3,new Car("003","福特",150000,"红色"));
        cars.put(driver4,new Car("004","宝马",600000,"绿色"));
        //通过司机查找汽车
        //默认HashMap通过Driver对象的内存地址查找汽车的
//        Car car = cars.get(driver3);
        //new 新的对象，内存地址不同，无法找到value
        Car car = cars.get(new Driver("老王",40,"男"));
        System.out.println("找到汽车：" + car);
        Car car2 = cars.get(new Driver("老李",45,"男"));
        System.out.println("找到汽车：" + car2);
    }
}
